# Copyright (C) Kumo inc. and its affiliates.
# Author: Jeff.li lijippy@163.com
# All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https:#www.gnu.org/licenses/>.
#
# Build the test and build container for presto_cpp
ARG image=ghcr.io/facebookincubator/pollux-dev:centos9
FROM $image

COPY scripts/setup-helper-functions.sh /
COPY scripts/setup-adapters.sh /
COPY scripts/setup-centos9.sh /
RUN mkdir build && \
    ( \
      cd build && \
      source /opt/rh/gcc-toolset-12/enable && \
      bash /setup-adapters.sh && \
      source /setup-centos9.sh && \
      install_cuda 12.8 \
    ) && \
    rm -rf build && dnf remove -y conda && dnf clean all

# put CUDA binaries on the PATH
ENV PATH=/usr/local/cuda/bin:${PATH}

# configuration for nvidia-container-toolkit
ENV NVIDIA_VISIBLE_DEVICES=all
ENV NVIDIA_DRIVER_CAPABILITIES="compute,utility"

# install miniforge
RUN curl -L -o /tmp/miniforge.sh https://github.com/conda-forge/miniforge/releases/download/23.11.0-0/Mambaforge-23.11.0-0-Linux-x86_64.sh && \
    bash /tmp/miniforge.sh -b -p /opt/miniforge && \
    rm /tmp/miniforge.sh
ENV PATH=/opt/miniforge/condabin:${PATH}

# install test dependencies
RUN mamba create -y --name adapters python=3.8
SHELL ["mamba", "run", "-n", "adapters", "/bin/bash", "-c"]

RUN pip install https://github.com/googleapis/storage-testbench/archive/refs/tags/v0.36.0.tar.gz
RUN mamba install -y nodejs
RUN npm install -g azurite

ENV HADOOP_HOME=/usr/local/hadoop \
    HADOOP_ROOT_LOGGER="WARN,DRFA" \
    LC_ALL=C \
    PATH=/usr/local/hadoop/bin:${PATH} \
    JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk \
    PATH=/usr/lib/jvm/java-1.8.0-openjdk/bin:${PATH}

COPY scripts/setup-classpath.sh /
ENTRYPOINT ["/bin/bash", "-c", "source /setup-classpath.sh && source /opt/rh/gcc-toolset-12/enable && exec \"$@\"", "--"]
CMD ["/bin/bash"]
